﻿Clear-Host;

$ComputerName= @();
$cn= New-Object System.Data.SqlClient.SQLConnection("Data Source=BBA-Phl-vDBAdmin.BBAAviation.net;Integrated Security=SSPI;"); $cn.Open();
$cmd= New-Object System.Data.SqlClient.SqlCommand("SELECT ServerName FROM dbo.ServerList WHERE Label NOT LIKE N'%(-)' ORDER BY Category, ServerName;", $cn);
$r= $cmd.ExecuteReader();
while ($r.read()) {$ComputerName+= $r[0].Split("\")[0];}
$r.Close(); $cn.Close();

foreach ($Computer in $ComputerName) {
    Write-Output $Computer;
#	Copy-Item -LiteralPath "\\IT\Information Technology\DBA\Certificate\Certificates.msc" -Destination "\\$Computer\C$\Users\Public\Desktop";
};

Invoke-Command -Verbose -ComputerName $ComputerName -ScriptBlock {
    Remove-Item -Path "C:\Users\Public\Desktop\Certificates (Local Computer).msc";
    Remove-Item -Path "C:\Users\EZVHNL\Desktop\*";
    &"$env:windir\system32\schtasks.exe" /f /delete /tn "Check SQL Server Certificate Configuration";
};